//
//  SKYBattery.m
//  SkyonSDK
//
//  Created by macbook on 2018/5/8.
//  Copyright © 2018年 Skyon. All rights reserved.
//

#import "SKYBattery.h"
#import <UIKit/UIKit.h>
#import <SKYDeviceInfoList.h>

@implementation SKYBattery

+ (void)startMonitoring {
    [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
}

+ (void)stopMonitoring {
    [[UIDevice currentDevice] setBatteryMonitoringEnabled:NO];
}

+ (NSString *)getBatteryLevel {
    float batteryLevel = [[UIDevice currentDevice] batteryLevel];
    return [NSString stringWithFormat:@"%0.0f",batteryLevel*100];
}

+ (NSString *)getBatteryState {
    float batteryLevel = [[UIDevice currentDevice] batteryLevel];
    NSString *sState = @"";
    switch ([[UIDevice currentDevice] batteryState]) {
        case UIDeviceBatteryStateCharging:
            if (batteryLevel == 100) {
                sState = @"充满";
            } else {
                sState = @"充电状态";
            }
            break;
        case UIDeviceBatteryStateFull:
            sState = @"充满";
            break;
        case UIDeviceBatteryStateUnplugged:
            sState = @"放电状态";
            break;
        case UIDeviceBatteryStateUnknown:
            sState = @"未知状态";
            break;
    }
    return sState;
}

+ (BOOL)batteryIsCharging {
    return [[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateCharging ? YES : NO;
}

+ (NSUInteger)getBatteryCapacity {
    return [SKYDeviceInfoList getBatteryCapacity];
}

+ (NSUInteger)getBatteryCapacityLeft {
    float batteryLevel = [[UIDevice currentDevice] batteryLevel];
    return round([SKYDeviceInfoList getBatteryCapacity] * batteryLevel);
}

@end
